package com.qc.wintrax.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.qc.wintrax.R;


/**
 * Created by jianxiong on 2016/2/25.
 */
public class CustomActionBar extends RelativeLayout {

    private ImageView leftImage;
    private ImageView rightImage;
    private TextView textView;
    private TextView textRight;

    public void setLeftImage(ImageView leftImage) {
        this.leftImage = leftImage;
    }

    public void setRightImage(ImageView rightImage) {
        this.rightImage = rightImage;
    }

    public void setTextRight(TextView textRight) {
        this.textRight = textRight;
    }

//    public void setTextRightColor(TextView textRightColor) {
//        this.textRightColor = textRightColor;
//    }

    public ImageView getLeftImage() {
        return leftImage;

    }

    public ImageView getRightImage() {
        return rightImage;
    }

    public TextView getTextRight() {
        return textRight;
    }

    public TextView getTextView() {
        return textView;
    }

    OnClickListener onLeftImageClickListener;
    OnClickListener onRightImageClickListener;
    OnClickListener onRightTextClickListener;

    public CustomActionBar(Context context) {
        super(context);
    }

    public CustomActionBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.custom_action_bar, this, true);
        leftImage = (ImageView) findViewById(R.id.leftImage);
        rightImage = (ImageView) findViewById(R.id.rightImage);
        textView = (TextView) findViewById(R.id.textView);
        textRight = (TextView) findViewById(R.id.rightTxt);

        leftImage.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onLeftImageClickListener != null) {
                    onLeftImageClickListener.onClick(view);
                }
            }
        });

        rightImage.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onRightImageClickListener != null) {
                    onRightImageClickListener.onClick(view);
                }
            }
        });

        textRight.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onRightTextClickListener != null) {
                    onRightTextClickListener.onClick(view);
                }
            }
        });
    }

    /**
     * @author fujianxiong
     * @Description:(给左边image设置图片) create at  15:30
     **/
    public void setLeftImageResource(int resId) {
        leftImage.setImageResource(resId);
    }

    /**
     * @author fujianxiong
     * @Description:(给右边image设置图片) create at  15:32
     **/
    public void setRightImageResource(int resId) {
        rightImage.setImageResource(resId);
    }

    public void setTextView(String text) {
        textView.setText(text);
    }

    public void setRightTextView(String text) {
        textRight.setText(text);
    }

    public void setRightTextColor(int resId) {
        textRight.setTextColor(resId);
    }

    public void setRightTextVisibility(int visibility) {
        textRight.setVisibility(visibility);
    }

    public void setTextViewVisibility(int visibility) {
        textView.setVisibility(visibility);
    }

    public void setRightImageVisibility(int visibility) {
        rightImage.setVisibility(visibility);
    }


    public void setRightTextEnabled(boolean enabled) {
        textRight.setFocusable(enabled);

    }


    public void setOnLeftImageClickListener(OnClickListener onLeftImageClickListener) {
        this.onLeftImageClickListener = onLeftImageClickListener;
        if (leftImage != null) {
            leftImage.setOnClickListener(onLeftImageClickListener);
        }
    }

    public void setOnRightImageClickListener(OnClickListener onRightImageClickListener) {
        this.onRightImageClickListener = onRightImageClickListener;
        if (leftImage != null) {
            rightImage.setOnClickListener(onRightImageClickListener);
        }
    }

    public void setOnRightTextClickListener(OnClickListener onRightTextClickListener) {
        this.onRightTextClickListener = onRightTextClickListener;
        if (textRight != null) {
            textRight.setOnClickListener(onRightTextClickListener);
        }
    }
}
